Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOC: Document existing functionality of pandas.DataFrame.to_sql() #11886 #26795

Merged
merged 20 commits into from
Aug 30, 2019
Merged

DOC: Document existing functionality of pandas.DataFrame.to_sql() #11886 #26795

merged 20 commits into from
Aug 30, 2019

Conversation

oguzhanogreden
Copy link
Contributor

@oguzhanogreden
Copy link
Contributor Author

The documentation related notes on "Contribute to Pandas" are not in a very helpful state. I haven't yet managed to build and check if this appears at pandas.DataFrame.to_sql(). I suppose it would, so I went on with the PR.

Next one in line is documentation contribution notes :)

Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor doc nits. Any interest in adding an annotation while you are looking at this?

pandas/core/generic.py Outdated Show resolved Hide resolved
pandas/core/generic.py Outdated Show resolved Hide resolved
@WillAyd WillAyd added the Docs label Jun 11, 2019
@codecov
Copy link

codecov bot commented Jun 11, 2019

Codecov Report

❗ No coverage uploaded for pull request base (master@bc65fe6). Click here to learn what that means.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master   #26795   +/-   ##
=========================================
  Coverage          ?   91.87%           
=========================================
  Files             ?      179           
  Lines             ?    50698           
  Branches          ?        0           
=========================================
  Hits              ?    46578           
  Misses            ?     4120           
  Partials          ?        0
Flag Coverage Δ
#multiple 90.46% <100%> (?)
#single 41.1% <100%> (?)
Impacted Files Coverage Δ
pandas/core/generic.py 94.2% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bc65fe6...efa97be. Read the comment docs.

@oguzhanogreden
Copy link
Contributor Author

I'll add the annotations.

@WillAyd
Copy link
Member

WillAyd commented Jun 12, 2019

I'll add the annotations.

Cool thanks. If it ends up being a lot of trouble we could go forward with just this for now and address annotations in separate PRs. lmk

@pep8speaks
Copy link

pep8speaks commented Jun 13, 2019

Hello @oguzhanogreden! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2019-08-29 10:01:59 UTC

index: bool = True,
index_label: Optional[Union[str, List[str]]] = None,
chunksize: Optional[int] = None, dtype: Union[dict] = None,
method: Union[str, Callable] = None):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see the Callable annotation here. It may be possible to be more precise here. I looked around a bit, finally decided not to write the most complex type annotation in the code base 🤷‍♂

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be able to match this up with exact types (see the documentation for method)

Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice job!

pandas/core/generic.py Outdated Show resolved Hide resolved
schema: Optional[str] = None, if_exists: str = 'fail',
index: bool = True,
index_label: Optional[Union[str, List[str]]] = None,
chunksize: Optional[int] = None, dtype: Union[dict] = None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For dtype use Dict[Any, Dtype] (Dict from typing, Dtype from pandas._typing)

index: bool = True,
index_label: Optional[Union[str, List[str]]] = None,
chunksize: Optional[int] = None, dtype: Union[dict] = None,
method: Union[str, Callable] = None):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be able to match this up with exact types (see the documentation for method)

Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the thorough investigation and input on this so far

pandas/core/generic.py Outdated Show resolved Hide resolved
@oguzhanogreden
Copy link
Contributor Author

Oops... circular import. I don't feel comfortable with the code base enough to work around this. I'll replace the annotation for pd_table with Any unless you have a suggestion.

@WillAyd
Copy link
Member

WillAyd commented Jun 15, 2019

OK sure. Any is not very useful as an annotation but can come back to that piece later; I think the rest of this is great

@WillAyd WillAyd added the Typing type annotations, mypy/pyright type checking label Jun 15, 2019
@WillAyd
Copy link
Member

WillAyd commented Jun 15, 2019

Just put a comment like TODO: replace Any with SQLTable if circular import resolved

@oguzhanogreden
Copy link
Contributor Author

Sure, thanks for the way out here and patient help!

For completeness...

method: Union[str, Callable[[Any, Any, ...

can be replaced with

method: Union[str, Callable[[pandas.io.sql.SQLTable, Union[sqlalchemy.engine.Connection, sqlalchemy.engine.Engine], ...

This can be done when:

  • SQLTable can be imported without causing circular import,
  • sqlalchemy types are available for type annotations.

# TODO: Replace `Callable[[Any, Any, ...` when SQLTable and sqlalchemy
# can be imported. SQLTable can't be imported due to circular import.
# sqlalchemy can't be imported since it's an optional dependency.
def to_sql(self, name: str, con,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry should have asked this before but can you put each parameter on a separate line? Will help with readability

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Also added Any to con= and added explanation to the note so that less thinking is required later.

@@ -50,6 +51,9 @@
from pandas.io.formats.printing import pprint_thing
from pandas.tseries.frequencies import to_offset

# mypy confuses the `bool()`` method of NDFrame
_bool = bool
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea this is unfortunate and something we've seen before:

#26029 (comment)

The alias is the suggested approach so no change required here I think, but cc @jreback for visibility

Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm @jreback

pandas/core/generic.py Outdated Show resolved Hide resolved
@oguzhanogreden
Copy link
Contributor Author

I expected that VSCode would let me know of updates in master. The last conflict was due to that and I missed it before hitting resolve!

@WillAyd
Copy link
Member

WillAyd commented Jun 17, 2019 via email

@oguzhanogreden
Copy link
Contributor Author

Of course, should've thought! :) This has been very educative for me, thanks.

Once you folks decide how to treat these annotations, I'll move on as you suggest.

pandas/core/generic.py Outdated Show resolved Hide resolved
pandas/core/generic.py Outdated Show resolved Hide resolved
@oguzhanogreden
Copy link
Contributor Author

oguzhanogreden commented Jul 31, 2019

I want to move this forward.

We have two issues:

  1. SQLTable can't be imported due to circular import,
  2. sqlalchemy.engine.Engine can't be imported due to it being an optional dependency.

Quick recap of what happened so far: Initially we added Any for these and left comments. Then I was pointed to quoting these with backticks, which led me down to TYPE_CHECKING conditional. It turned out that's something you don't want.

I will go back to "Any and comments" solution for SQLTable and sqlalchemy.engine.Engine. I think this is also what's implied by @WillAyd's last request changes. Is this acceptable by the group at this stage? If there is not a consensus, I'd like to remove type annotations from this PR and focus on the initial goal.

Let me know!

@WillAyd
Copy link
Member

WillAyd commented Aug 26, 2019

I would say go ahead and remove the complicated annotations that are tripping this up and we can get this in

@oguzhanogreden
Copy link
Contributor Author

This should be ready.

@TomAugspurger TomAugspurger added this to the 1.0 milestone Aug 30, 2019
@TomAugspurger TomAugspurger merged commit 621ad9d into pandas-dev:master Aug 30, 2019
@TomAugspurger
Copy link
Contributor

Thanks! Congrats on your first PR to pandas!

@WillAyd
Copy link
Member

WillAyd commented Aug 30, 2019

Yea nice job @oguzhanogreden thanks for sticking through the back and forth.

@oguzhanogreden
Copy link
Contributor Author

Great, thanks for your support and patience as well!

@oguzhanogreden oguzhanogreden deleted the docs-pr11886 branch August 31, 2019 19:15
MarcoGorelli pushed a commit to MarcoGorelli/pandas that referenced this pull request Sep 3, 2019
proost pushed a commit to proost/pandas that referenced this pull request Dec 19, 2019
proost pushed a commit to proost/pandas that referenced this pull request Dec 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Docs Typing type annotations, mypy/pyright type checking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants